package com.nongda.controller;

import com.nongda.dto.ShangPinDto;
import com.nongda.dto.ShangPinPageDto;
import com.nongda.pojo.ShangPin;
import com.nongda.result.PageResult;
import com.nongda.result.Result;
import com.nongda.service.ShangPinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/shangpin")
@Slf4j
public class ShangPinController {
    @Autowired
    ShangPinService shangPinService;
    @PutMapping
    public Result insert(@RequestBody ShangPinDto shangPinDto){
    shangPinService.insert(shangPinDto);
    return Result.success("添加成功");
    }
    @PostMapping
    public Result update(@RequestBody ShangPin shangPin){
        shangPinService.update(shangPin);
        return Result.success("修改成功");
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        shangPinService.delete(id);
        return Result.success("删除成功");
    }
    @GetMapping
    public Result<PageResult>page(@RequestBody ShangPinPageDto shangPinPageDto){
    PageResult pageResult=shangPinService.page(shangPinPageDto);
    return Result.success(pageResult);
    }

}
